var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/Sorter/index.tsx
var Sorter_exports = {};
__export(Sorter_exports, {
  default: () => Sorter_default
});
module.exports = __toCommonJS(Sorter_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_style = require("antd/es/space/style/index.js");
var import_icons = require("@ant-design/icons");
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var Sorter = ({
  value,
  onChange,
  disabled,
  children
}) => {
  const handleClick = (0, import_react.useCallback)(() => {
    if (disabled)
      return;
    const allowedValues = ["ASC", "DESC", void 0];
    const index = allowedValues.indexOf(value);
    onChange == null ? void 0 : onChange(allowedValues[(index + 1) % 3]);
  }, [disabled, value, onChange]);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("szzj-sorter", {
        "szzj-sorter-disabled": disabled
      }),
      onClick: handleClick
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-sorter-content" }, children),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "szzj-sorter-icons" }, /* @__PURE__ */ import_react.default.createElement(
      import_icons.CaretUpOutlined,
      {
        className: (0, import_classnames.default)({ actived: value === "ASC" }),
        onClick: (event) => {
          if (disabled)
            return;
          event.stopPropagation();
          onChange == null ? void 0 : onChange("ASC");
        }
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_icons.CaretDownOutlined,
      {
        className: (0, import_classnames.default)({ actived: value === "DESC" }),
        onClick: (event) => {
          if (disabled)
            return;
          event.stopPropagation();
          onChange == null ? void 0 : onChange("DESC");
        }
      }
    ))
  );
};
var Group = ({
  defaultValue,
  children,
  onChange,
  value,
  disabled,
  options
}) => {
  const [sorter, setSorter] = (0, import_react.useState)(defaultValue);
  (0, import_react.useEffect)(() => {
    if (value !== sorter) {
      if (value !== void 0 || sorter !== defaultValue) {
        setSorter(value);
      }
    }
  }, [value]);
  const childNodes = (options == null ? void 0 : options.length) ? options.map((item) => /* @__PURE__ */ import_react.default.createElement(Sorter, { key: item.value }, item.label)) : children;
  return /* @__PURE__ */ import_react.default.createElement(import_antd.Space, null, import_react.Children.map(childNodes, (child) => {
    return (0, import_react.cloneElement)(child, {
      value: (sorter == null ? void 0 : sorter.field) === child.key ? sorter == null ? void 0 : sorter.sortBy : void 0,
      onChange: (value2) => {
        const newValue = {
          field: child.key,
          sortBy: value2
        };
        setSorter(newValue);
        onChange == null ? void 0 : onChange(newValue);
      },
      disabled: "disabled" in child.props ? child.props.disabled : disabled
    });
  }));
};
Sorter.Group = Group;
var Sorter_default = Sorter;
